package com.atzc.utils.map;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.atzc.bean.CarDetailLogBean;
import org.apache.flink.api.common.functions.MapFunction;


public class ParseCarDetailLogBeanMap implements MapFunction<String, CarDetailLogBean>{

    String splitPoint = "is:";

    public ParseCarDetailLogBeanMap() {
    }

    public ParseCarDetailLogBeanMap(String splitPoint) {
        this.splitPoint = splitPoint;
    }


    @Override
    public CarDetailLogBean map(String log) throws Exception {
        // 切割出日志
        try {
            String carDetailLog = log.split(splitPoint)[1];
            // 首先过滤JSON异常的数据
            return JSONObject.parseObject(carDetailLog, CarDetailLogBean.class);
        }catch (IndexOutOfBoundsException indexOutOfBoundsException){
            System.out.println("过滤短租车辆详情页日志数据里面没有 is:");
            return null;
        }catch (JSONException e){
            //TODO
            System.out.println("JSON转换格式异常");
            return null;
        }
    }
}
